﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NXDO.Data.Factory;
using NXDO.WebAPI.Controllers;
using System;
using System.Collections.Generic;
using TDM.DbData.DataEntity;
using TDM.WebBase;
using TDM.WebBiz.TestData;
using TDM.WebSvr.Controllers.TestData.File;

namespace TDM.WebSvr.Controllers.TestData
{
    /// <summary>
    /// 任务描述文件查询
    /// </summary>
    [AllowAnonymous]
    public class TestTaskFileController : ApiDbEntityController<TestTaskFile,long>
    {
        /// <summary>
        /// 获取试验结果的文件集合
        /// </summary>
        /// <param name="LaserResultID"></param>
        /// <returns></returns>
        [HttpGet]
        public IEnumerable<TestTaskFile> GetTestTaskFiles(long taskID)
        {
            var sql = "select * from TestTaskFile where taskID = {0}";
            return DbHelper.SetCommand(sql, taskID).ExecuteEntity<TestTaskFile>();
        }

        protected override string GetPkName()
        {
            return "TaskFID";
        }

        protected override string GetTableName()
        {
            return "TestTaskFile";
        }

        /// <summary>
        /// 返回所有图片的路径
        /// </summary>
        /// <param name="taskid"></param>
        /// <returns></returns>
        [HttpGet]
        public IEnumerable<TestTaskFileImg> QueryTaskImgs(long taskid)
        {
            var rs = TestTaskFileHelper.QueryTaskImgs(taskid);
            return rs;
            
        }

        /// <summary>
        /// 删除任务图片文件
        /// </summary>
        /// <param name="fileIDs"></param>
        [HttpPost]
        public void DeleteTestTaskImgFile([FromBody] List<long> fileIDs)
        {
            try
            {
                TestTaskFileHelper.DeleteFile(fileIDs);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
    
}
